package cash_access;

import java.io.Serializable;
import mware_lib.ISkeleton;

public class TransactionSkeleton implements ISkeleton {
  private TransactionImplBase transaction;

  public TransactionSkeleton(TransactionImplBase transaction) {
    this.transaction = transaction;
  }
  
  @Override
  public Serializable invokeMethod(String methodName, Serializable[] params) {
    switch(methodName) {
      case "deposit":
        try {
          transaction.deposit((String)params[0], (double)params[1]);
        } catch (RuntimeException r) {
          return r;
        }
        break;
      case "withdraw":
        try {
          transaction.withdraw((String)params[0], (double)params[1]);
        } catch (OverdraftException | RuntimeException ex) {
          return ex;
        }
        break;
      case "getBalance":
        try {
          return transaction.getBalance((String)params[0]);
        } catch(RuntimeException r) {
          return r;
        }
    }
    return null; //Sollte nie erreicht werden
  }

}
